#include "Camera.h"
#include "World.h"

namespace TG
{
	Camera::Camera():position(0,0,-5), target(0,0,0), up(0, 1, 0), _viewport(0, 0, 1, 1)
	{
	}

	Camera::~Camera()
	{
	}

	void Camera::setTarget(vec3 &target)
	{
		this->target = target;
	}

	void Camera::setUp(vec3 &up)
	{
		this->up = up;
	}

	void Camera::setPosition(vec3 &position)
	{
		this->position = position;
	}

	mat4x4 Camera::getViewMatrix()
	{
		//mat4x4 m = rotateZ(position.z) * rotateY(position.y) * rotateX(position.x);
		//
		//vec3 u = m * vec3::right;
		//vec3 v = m * vec3::up;
		//vec3 n = m * vec3::back;
		//
		//return coordinate(u, v, n, position);
		return lookAt(position, target, up);
	}

	mat4x4 Camera::getProjMatrix()
	{
		return perspective(fov, aspect, nearPlane, farPlane);
	}

	vec4 Camera::getViewport()
	{
		return _viewport;
	}

	vec3 Camera::forward()
	{
		return normalize(target - position);
	}

	bool Camera::operator<(const Camera &c)
	{
		return depth < c.depth ? true : false;
	}
}